<?php

namespace App\Jobs;

use App\User;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use App\Jobs\Sendmail;


class SendReminderEmail implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
      /**
     * 任务最大尝试次数。
     *
     * @var int
     */
    public $tries = 1;

    /**
     * 任务运行的超时时间。
     *
     * @var int
     */
    public $timeout = 60;


    protected $user;
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($user)
    {
        //
        $this->user = $user;
    } 

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        //
        \Log::useDailyFiles(storage_path('logs/error.log'));
        \Log::info("发送邮件到");
        $content = $this->user->username . "发表了新文章" . time() . "\n";
       
        file_put_contents('notice.txt',$content, FILE_APPEND);


        // 如果第一次怎么都不成功的话  延时另外发送队列 
        $queues = (new Sendmail())->onQueue('sendmail');
        dispatch($queues);
        //file_put_contents('not.txt', 'ha',FILE_APPEND);
        // for ($i=0; $i < 5 ; $i++) { 
        //     echo $i;
        // }
    }
}
